package cn.pkubangbang.demo.democontact.entity;

import java.util.Objects;

/**
 * @Author: zhangzhenbang@k2data.com.cn
 * @Date: 2018-08-23 19:21
 */
public class Contact {

    private Integer id;
    private Person person1;
    private Person person2;

    public Contact() {
    }

    public Contact(Integer id, Person person1, Person person2) {
        this.id = id;
        this.person1 = person1;
        this.person2 = person2;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Person getPerson1() {
        return person1;
    }

    public void setPerson1(Person person1) {
        this.person1 = person1;
    }

    public Person getPerson2() {
        return person2;
    }

    public void setPerson2(Person person2) {
        this.person2 = person2;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Contact contact = (Contact) o;
        return this.person1.equals(contact.person1) && this.person2.equals(contact.person2)
            || this.person2.equals(contact.person1) && this.person1.equals(contact.person2);
    }

    @Override
    public int hashCode() {

        return Objects.hash(getPerson1(), getPerson2()) + Objects.hash(getPerson2(), getPerson1());
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Contact{");
        sb.append("id=").append(id);
        sb.append(", person1=").append(person1);
        sb.append(", person2=").append(person2);
        sb.append('}');
        return sb.toString();
    }
}
